package com.imooc.miaosha.result;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 模块描述: <br>
 * (返回码和消息)
 *
 * @Author: Mr. xyb
 * @Date: 2019/4/14 14:16
 * @since: 1.8.0
 * @version: 1.0.0
 */
@Getter
@Setter
@ToString
public class CodeMsg {

    private int code;

    private String msg;

    public CodeMsg(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public CodeMsg(ResultEnums resultEnums) {
        this.code = resultEnums.getCode();
        this.msg = resultEnums.getMsg();
    }

    /**
     * 拼接全局异常的信息
     *
     * @param arg
     * @return
     */
    public CodeMsg fillArgs(Object... arg) {
        int code = this.code;
        String msg = String.format(this.msg, arg);
        return new CodeMsg(code, msg);

    }

}
